//
//  MainViewController.m
//  PlayDAs
//
//  Created by 周莹 on 15/12/15.
//  Copyright © 2015年 周莹. All rights reserved.
//
#import "PopoverView.h"
#import "MainViewController.h"
#import "AppDelegate.h"
#import "PlayViewController.h"
#import "SectionViewController.h"
#import "MyViewController.h"
@interface MainViewController ()<UITabBarControllerDelegate>


@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"玩坏广告";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 20, 18);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"11.png"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(openOrCloseLeftList) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
    
    
    
    
    UIButton *leftB = [UIButton buttonWithType:UIButtonTypeCustom];
    leftB.frame = CGRectMake(0, 0, 20, 18);
    [leftB setBackgroundImage:[UIImage imageNamed:@"加号.png"] forState:UIControlStateNormal];
    [leftB addTarget:self action:@selector(leftBDidPOP) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftB];
    
    

    
    
    
    
    tabBarCtrl = [[UITabBarController alloc] init];//要加入的TabBarController
    tabBarCtrl.delegate = self;
    PlayViewController * playC = [[PlayViewController  alloc] init];
    
    playC.title = @"玩赚";
   // playC.view.backgroundColor = [UIColor blueColor];
    playC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"玩赚" image: nil tag:1];//自定义tabBarItem,可以贴tabBarItem背景图片，如果不写，tabBarItem的标签将显示为firstViewCtl.title内容
    
    
    SectionViewController  *secoentC = [[SectionViewController alloc] init];
    secoentC.title = @"收藏";
   // secoentC.view.backgroundColor = [UIColor redColor];
    //secoentC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",8]; //tabBarItem红色小圈中显示数字
    secoentC.tabBarItem.tag = 2; //加标示
    
    
    MyViewController  *MYC = [[MyViewController alloc] init];
    MYC.title = @"我";
    MYC.view.backgroundColor = [UIColor blueColor];
    //MYC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",8]; //tabBarItem红色小圈中显示数字
    MYC.tabBarItem.tag = 3; //加标示

    
    
    
    
    NSArray *arryViewContrller = [NSArray arrayWithObjects:playC, secoentC,MYC,nil];
    tabBarCtrl.viewControllers = arryViewContrller;
    tabBarCtrl.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    
    [self.view addSubview:tabBarCtrl.view];
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void) openOrCloseLeftList
{
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (tempAppDelegate.LeftSlideVC.closed)
    {
        [tempAppDelegate.LeftSlideVC openLeftView];
    }
    else
    {
        [tempAppDelegate.LeftSlideVC closeLeftView];
    }
}


-(void)leftBDidPOP{

    CGPoint point = CGPointMake(self.view.frame.size.height, self.view.frame.size.width/5);
    NSArray *titles = @[@"分享", @"扫一扫", @"帮助",@"反馈"];
    PopoverView *pop = [[PopoverView alloc] initWithPoint:point titles:titles images:nil];
    pop.selectRowAtIndex = ^(NSInteger index){
        NSLog(@"select index:%ld", (long)index);
    };
    [pop show];



}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:NO];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:YES];
}
//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
//{
//    
//    NSString *strTitle = viewController.title;
//   
//    if(1 == viewController.tabBarItem.tag)
//        
//        　　　{
//            
////            viewController.tabBarItem.badgeValue = [CFStringCreateWithFormat:@"%d", rand()%100];
////            
//        }
//    
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
